require "prefabutil"

local assets =
{
	Asset("ANIM", "anim/m_sword.zip"),
	Asset("ATLAS", "images/inventoryimages/m_sword.xml"),
}

local prefabs =
{
} 

local function onequip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_object", "m_sword", "swap_m_sword")
    owner.AnimState:Show("ARM_carry") 
    owner.AnimState:Hide("ARM_normal")
end

local function onunequip(inst, owner) 
    owner.AnimState:Hide("ARM_carry") 
    owner.AnimState:Show("ARM_normal") 
end

local function fn()
	local inst = CreateEntity()

	inst.entity:AddTransform()
	local anim = inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    anim:SetBank("windyknife")
    anim:SetBuild("windyknife")
    anim:PlayAnimation("idle")

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("tool")
    inst.components.tool:SetAction(ACTIONS.CHOP, 2)
    inst.components.tool:SetAction(ACTIONS.MINE, 2)
	if TUNING.canhammer == 1 then
    inst.components.tool:SetAction(ACTIONS.HAMMER,1)
	end
	if TUNING.candig == 1 then
    inst.components.tool:SetAction(ACTIONS.DIG,2)
	end

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(27)

    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
    inst.components.equippable.walkspeedmult = TUNING.CANE_SPEED_MULT
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/m_sword.xml"

    inst:AddTag("playerowned")

	return inst
end

return Prefab("m_sword", fn, assets, prefabs)
